{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "aa070ae8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ec7f2ed",
   "metadata": {},
   "source": [
    "## 运行快捷键\n",
    " ctrl + enter\n",
    " \n",
    " alt + enter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "18e59acd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1500100001</td>\n",
       "      <td>施笑槐</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1500100002</td>\n",
       "      <td>吕金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1500100003</td>\n",
       "      <td>单乐蕊</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1500100004</td>\n",
       "      <td>葛德曜</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1500100005</td>\n",
       "      <td>宣谷芹</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1500100996</td>\n",
       "      <td>厉运凡</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1500100997</td>\n",
       "      <td>陶敬曦</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1500100998</td>\n",
       "      <td>容昆宇</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1500100999</td>\n",
       "      <td>钟绮晴</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1500101000</td>\n",
       "      <td>符瑞渊</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             id name  age gender clazz\n",
       "0    1500100001  施笑槐   22      女  文科六班\n",
       "1    1500100002  吕金鹏   24      男  文科六班\n",
       "2    1500100003  单乐蕊   22      女  理科六班\n",
       "3    1500100004  葛德曜   24      男  理科三班\n",
       "4    1500100005  宣谷芹   22      女  理科五班\n",
       "..          ...  ...  ...    ...   ...\n",
       "995  1500100996  厉运凡   24      男  文科三班\n",
       "996  1500100997  陶敬曦   21      男  理科六班\n",
       "997  1500100998  容昆宇   22      男  理科四班\n",
       "998  1500100999  钟绮晴   23      女  文科五班\n",
       "999  1500101000  符瑞渊   23      男  理科六班\n",
       "\n",
       "[1000 rows x 5 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读写 CSV文件\n",
    "# CSV文件默认分隔符为, 并且names未指定情况下，默认第一行为列名称\n",
    "student = pd.read_csv(\"../data/students.csv\",names=['id','name','age','gender','clazz'])\n",
    "student"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "95107916",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名   语文   数学   英语   总分  班名次\n",
       "0    杨璐  131  143  144  418    1\n",
       "1    王雪  131  135  144  410    2\n",
       "2   韩林霖  127  139  142  408    3\n",
       "3   沙龙逸  123  148  136  407    4\n",
       "4   李鉴学  126  135  140  401    5\n",
       "..  ...  ...  ...  ...  ...  ...\n",
       "63   赵森   90   29   64  183   64\n",
       "64  满朝升   78   45   47  170   65\n",
       "65  李忠浩   86   32   46  164   66\n",
       "66  侯禹志   75   23   34  132   67\n",
       "67  尹鸿涛   66   23   34  123   68\n",
       "\n",
       "[68 rows x 6 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_grade = pd.read_csv(\"../data/student_grade.txt\",sep='\\t')\n",
    "student_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e1589057",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "24888a45",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['男', '女', '男', '男', '男', '女', '男', '男', '男', '男', '男', '女', '男',\n",
       "       '男', '女', '男', '女', '女', '男', '男', '男', '男', '女', '男', '女', '男',\n",
       "       '男', '女', '男', '男', '女', '女', '男', '女', '男', '女', '女', '男', '女',\n",
       "       '女', '女', '男', '女', '女', '女', '女', '男', '男', '女', '男', '男', '女',\n",
       "       '男', '女', '男', '男', '男', '男', '女', '男', '男', '女', '女', '男', '男',\n",
       "       '男', '男', '男'], dtype='<U1')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.choice(['男','女'],68)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "dcfc9a0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "      <th>性别</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名   语文   数学   英语   总分  班名次 性别\n",
       "0    杨璐  131  143  144  418    1  男\n",
       "1    王雪  131  135  144  410    2  女\n",
       "2   韩林霖  127  139  142  408    3  男\n",
       "3   沙龙逸  123  148  136  407    4  男\n",
       "4   李鉴学  126  135  140  401    5  女\n",
       "..  ...  ...  ...  ...  ...  ... ..\n",
       "63   赵森   90   29   64  183   64  男\n",
       "64  满朝升   78   45   47  170   65  男\n",
       "65  李忠浩   86   32   46  164   66  女\n",
       "66  侯禹志   75   23   34  132   67  女\n",
       "67  尹鸿涛   66   23   34  123   68  男\n",
       "\n",
       "[68 rows x 7 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataframe赋值操作\n",
    "student_grade['性别'] = np.random.choice(['男','女'],68)\n",
    "student_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1cf9e9e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 重命名操作\n",
    "# rename方法中需要用columns变量名指定字典 ，如果需要将原df进行替换 那么需要给的 inplace=True\n",
    "student_grade.rename(columns={'姓名':'name','语文':\"yw\",'数学':'sx','英语':'yy','总分':'zf','班名次':'mc','性别':'xb'},inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a85654e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "      <th>zf</th>\n",
       "      <th>mc</th>\n",
       "      <th>xb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   name   yw   sx   yy   zf  mc xb\n",
       "0    杨璐  131  143  144  418   1  男\n",
       "1    王雪  131  135  144  410   2  女\n",
       "2   韩林霖  127  139  142  408   3  男\n",
       "3   沙龙逸  123  148  136  407   4  男\n",
       "4   李鉴学  126  135  140  401   5  女\n",
       "..  ...  ...  ...  ...  ...  .. ..\n",
       "63   赵森   90   29   64  183  64  男\n",
       "64  满朝升   78   45   47  170  65  男\n",
       "65  李忠浩   86   32   46  164  66  女\n",
       "66  侯禹志   75   23   34  132  67  女\n",
       "67  尹鸿涛   66   23   34  123  68  男\n",
       "\n",
       "[68 rows x 7 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "89686561",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "      <th>zf</th>\n",
       "      <th>mc</th>\n",
       "      <th>xb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>韩雨萌</td>\n",
       "      <td>129</td>\n",
       "      <td>133</td>\n",
       "      <td>138</td>\n",
       "      <td>400</td>\n",
       "      <td>6</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>吕文卓</td>\n",
       "      <td>82</td>\n",
       "      <td>53</td>\n",
       "      <td>62</td>\n",
       "      <td>197</td>\n",
       "      <td>61</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>王晟煜</td>\n",
       "      <td>79</td>\n",
       "      <td>49</td>\n",
       "      <td>64</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   name   yw   sx   yy   zf  mc xb\n",
       "0    杨璐  131  143  144  418   1  男\n",
       "1    王雪  131  135  144  410   2  女\n",
       "5   韩雨萌  129  133  138  400   6  男\n",
       "2   韩林霖  127  139  142  408   3  男\n",
       "4   李鉴学  126  135  140  401   5  女\n",
       "..  ...  ...  ...  ...  ...  .. ..\n",
       "60  吕文卓   82   53   62  197  61  男\n",
       "61  王晟煜   79   49   64  192  62  男\n",
       "64  满朝升   78   45   47  170  65  男\n",
       "66  侯禹志   75   23   34  132  67  女\n",
       "67  尹鸿涛   66   23   34  123  68  男\n",
       "\n",
       "[68 rows x 7 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df排序函数sort_values \n",
    "# 参数 by中需要给定列名称  ,ascending=False表示倒序排列\n",
    "student_grade.sort_values(by=['yw','yy'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f65e1001",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取出前N行\n",
    "# head(n)\n",
    "student_one = student_grade.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "dc775171",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取出后N行\n",
    "# tail(n)\n",
    "student_two = student_grade.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "08b63a92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "      <th>zf</th>\n",
       "      <th>mc</th>\n",
       "      <th>xb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   name   yw   sx   yy   zf  mc xb\n",
       "0    杨璐  131  143  144  418   1  男\n",
       "1    王雪  131  135  144  410   2  女\n",
       "2   韩林霖  127  139  142  408   3  男\n",
       "3   沙龙逸  123  148  136  407   4  男\n",
       "4   李鉴学  126  135  140  401   5  女\n",
       "63   赵森   90   29   64  183  64  男\n",
       "64  满朝升   78   45   47  170  65  男\n",
       "65  李忠浩   86   32   46  164  66  女\n",
       "66  侯禹志   75   23   34  132  67  女\n",
       "67  尹鸿涛   66   23   34  123  68  男"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 合并两个df\n",
    "student_one.append(student_two)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "ab636872",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 68 entries, 0 to 67\n",
      "Data columns (total 7 columns):\n",
      " #   Column  Non-Null Count  Dtype \n",
      "---  ------  --------------  ----- \n",
      " 0   name    68 non-null     object\n",
      " 1   yw      68 non-null     int64 \n",
      " 2   sx      68 non-null     int64 \n",
      " 3   yy      68 non-null     int64 \n",
      " 4   zf      68 non-null     int64 \n",
      " 5   mc      68 non-null     int64 \n",
      " 6   xb      68 non-null     object\n",
      "dtypes: int64(5), object(2)\n",
      "memory usage: 3.8+ KB\n"
     ]
    }
   ],
   "source": [
    "student_grade.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "a1e6e34b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     优秀\n",
       "1     优秀\n",
       "2     优秀\n",
       "3     优秀\n",
       "4     优秀\n",
       "      ..\n",
       "63    较差\n",
       "64    很差\n",
       "65    很差\n",
       "66    很差\n",
       "67    很差\n",
       "Name: yy, Length: 68, dtype: category\n",
       "Categories (4, object): ['很差' < '较差' < '一般' < '优秀']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 散列函数\n",
    "pd.cut(student_grade.yy,4,labels=['很差','较差','一般','优秀'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "1cc546a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "      <th>zf</th>\n",
       "      <th>mc</th>\n",
       "      <th>xb</th>\n",
       "      <th>cut_test</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "      <td>男</td>\n",
       "      <td>较差</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   name   yw   sx   yy   zf  mc xb cut_test\n",
       "0    杨璐  131  143  144  418   1  男       优秀\n",
       "1    王雪  131  135  144  410   2  女       优秀\n",
       "2   韩林霖  127  139  142  408   3  男       优秀\n",
       "3   沙龙逸  123  148  136  407   4  男       优秀\n",
       "4   李鉴学  126  135  140  401   5  女       优秀\n",
       "..  ...  ...  ...  ...  ...  .. ..      ...\n",
       "63   赵森   90   29   64  183  64  男       较差\n",
       "64  满朝升   78   45   47  170  65  男       很差\n",
       "65  李忠浩   86   32   46  164  66  女       很差\n",
       "66  侯禹志   75   23   34  132  67  女       很差\n",
       "67  尹鸿涛   66   23   34  123  68  男       很差\n",
       "\n",
       "[68 rows x 8 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_grade['cut_test'] = pd.cut(student_grade.yy,4,labels=['很差','较差','一般','优秀'])\n",
    "student_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "f9f3bdcb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "优秀    37\n",
       "一般    14\n",
       "较差    11\n",
       "很差     6\n",
       "Name: cut_test, dtype: int64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计结果\n",
    "student_grade.cut_test.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "03a8a842",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "一般    27\n",
       "优秀    26\n",
       "较差    10\n",
       "很差     5\n",
       "Name: yw, dtype: int64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.cut(student_grade.yw,4,labels=['很差','较差','一般','优秀']).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "b518f7e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "      <th>zf</th>\n",
       "      <th>mc</th>\n",
       "      <th>xb</th>\n",
       "      <th>cut_test</th>\n",
       "      <th>yy_lab</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "      <td>男</td>\n",
       "      <td>较差</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   name   yw   sx   yy   zf  mc xb cut_test yy_lab\n",
       "0    杨璐  131  143  144  418   1  男       优秀     优秀\n",
       "1    王雪  131  135  144  410   2  女       优秀     优秀\n",
       "2   韩林霖  127  139  142  408   3  男       优秀     优秀\n",
       "3   沙龙逸  123  148  136  407   4  男       优秀     良好\n",
       "4   李鉴学  126  135  140  401   5  女       优秀     良好\n",
       "..  ...  ...  ...  ...  ...  .. ..      ...    ...\n",
       "63   赵森   90   29   64  183  64  男       较差    不及格\n",
       "64  满朝升   78   45   47  170  65  男       很差    不及格\n",
       "65  李忠浩   86   32   46  164  66  女       很差    不及格\n",
       "66  侯禹志   75   23   34  132  67  女       很差    不及格\n",
       "67  尹鸿涛   66   23   34  123  68  男       很差    不及格\n",
       "\n",
       "[68 rows x 9 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按规则进行离散切分\n",
    "# 对应区间进行打标\n",
    "student_grade['yy_lab'] = pd.cut(student_grade.yy,bins=[0,90,120,140,150],labels=['不及格','及格','良好','优秀'])\n",
    "student_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "ce64b2f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# to_csv 将 df 保存成 CSV格式文件 header表示是否保存列名称 index表示是否保存索引\n",
    "student_grade.to_csv(\"../data/student_grade_to_csv.txt\",encoding=\"UTF8\",header=False,index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd9e5704",
   "metadata": {},
   "source": [
    "## 函数应用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "a8b113ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "# map\n",
    "list1 = [1,2,3,4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "51e84237",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义方法将列表中的每一个元素取平方\n",
    "def func(x):\n",
    "    return x ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "2ca8a033",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(func,list1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "97a920e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Serise中使用Map\n",
    "# 对student_grade中的排名进行区分 前3名 学神  3-7名 学霸 7-65 普通学生 65-> 学渣\n",
    "\n",
    "def func2(x):\n",
    "    if(x<=3):\n",
    "        return \"学神\"\n",
    "    elif(x<=7):\n",
    "        return \"学霸\"\n",
    "    elif(x <=65):\n",
    "        return \"普通学生\"\n",
    "    else:\n",
    "        return \"学渣\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "6af8bb8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "student_grade['mc_lab'] = student_grade.mc.map(func2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "e710ef5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "      <th>zf</th>\n",
       "      <th>mc</th>\n",
       "      <th>xb</th>\n",
       "      <th>cut_test</th>\n",
       "      <th>yy_lab</th>\n",
       "      <th>mc_lab</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "      <td>学神</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "      <td>学神</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "      <td>学神</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>良好</td>\n",
       "      <td>学霸</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "      <td>良好</td>\n",
       "      <td>学霸</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "      <td>男</td>\n",
       "      <td>较差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>普通学生</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>普通学生</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>学渣</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>学渣</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>学渣</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   name   yw   sx   yy   zf  mc xb cut_test yy_lab mc_lab\n",
       "0    杨璐  131  143  144  418   1  男       优秀     优秀     学神\n",
       "1    王雪  131  135  144  410   2  女       优秀     优秀     学神\n",
       "2   韩林霖  127  139  142  408   3  男       优秀     优秀     学神\n",
       "3   沙龙逸  123  148  136  407   4  男       优秀     良好     学霸\n",
       "4   李鉴学  126  135  140  401   5  女       优秀     良好     学霸\n",
       "..  ...  ...  ...  ...  ...  .. ..      ...    ...    ...\n",
       "63   赵森   90   29   64  183  64  男       较差    不及格   普通学生\n",
       "64  满朝升   78   45   47  170  65  男       很差    不及格   普通学生\n",
       "65  李忠浩   86   32   46  164  66  女       很差    不及格     学渣\n",
       "66  侯禹志   75   23   34  132  67  女       很差    不及格     学渣\n",
       "67  尹鸿涛   66   23   34  123  68  男       很差    不及格     学渣\n",
       "\n",
       "[68 rows x 10 columns]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "b35c5287",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "      <th>zf</th>\n",
       "      <th>mc</th>\n",
       "      <th>xb</th>\n",
       "      <th>cut_test</th>\n",
       "      <th>yy_lab</th>\n",
       "      <th>mc_lab</th>\n",
       "      <th>name_x</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131</td>\n",
       "      <td>143</td>\n",
       "      <td>144</td>\n",
       "      <td>418</td>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "      <td>学神</td>\n",
       "      <td>杨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131</td>\n",
       "      <td>135</td>\n",
       "      <td>144</td>\n",
       "      <td>410</td>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "      <td>学神</td>\n",
       "      <td>王</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127</td>\n",
       "      <td>139</td>\n",
       "      <td>142</td>\n",
       "      <td>408</td>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>优秀</td>\n",
       "      <td>学神</td>\n",
       "      <td>韩</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>123</td>\n",
       "      <td>148</td>\n",
       "      <td>136</td>\n",
       "      <td>407</td>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "      <td>优秀</td>\n",
       "      <td>良好</td>\n",
       "      <td>学霸</td>\n",
       "      <td>沙</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>126</td>\n",
       "      <td>135</td>\n",
       "      <td>140</td>\n",
       "      <td>401</td>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "      <td>优秀</td>\n",
       "      <td>良好</td>\n",
       "      <td>学霸</td>\n",
       "      <td>李</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90</td>\n",
       "      <td>29</td>\n",
       "      <td>64</td>\n",
       "      <td>183</td>\n",
       "      <td>64</td>\n",
       "      <td>男</td>\n",
       "      <td>较差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>普通学生</td>\n",
       "      <td>赵</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78</td>\n",
       "      <td>45</td>\n",
       "      <td>47</td>\n",
       "      <td>170</td>\n",
       "      <td>65</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>普通学生</td>\n",
       "      <td>满</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "      <td>46</td>\n",
       "      <td>164</td>\n",
       "      <td>66</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>学渣</td>\n",
       "      <td>李</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>132</td>\n",
       "      <td>67</td>\n",
       "      <td>女</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>学渣</td>\n",
       "      <td>侯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "      <td>123</td>\n",
       "      <td>68</td>\n",
       "      <td>男</td>\n",
       "      <td>很差</td>\n",
       "      <td>不及格</td>\n",
       "      <td>学渣</td>\n",
       "      <td>尹</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   name   yw   sx   yy   zf  mc xb cut_test yy_lab mc_lab name_x\n",
       "0    杨璐  131  143  144  418   1  男       优秀     优秀     学神      杨\n",
       "1    王雪  131  135  144  410   2  女       优秀     优秀     学神      王\n",
       "2   韩林霖  127  139  142  408   3  男       优秀     优秀     学神      韩\n",
       "3   沙龙逸  123  148  136  407   4  男       优秀     良好     学霸      沙\n",
       "4   李鉴学  126  135  140  401   5  女       优秀     良好     学霸      李\n",
       "..  ...  ...  ...  ...  ...  .. ..      ...    ...    ...    ...\n",
       "63   赵森   90   29   64  183  64  男       较差    不及格   普通学生      赵\n",
       "64  满朝升   78   45   47  170  65  男       很差    不及格   普通学生      满\n",
       "65  李忠浩   86   32   46  164  66  女       很差    不及格     学渣      李\n",
       "66  侯禹志   75   23   34  132  67  女       很差    不及格     学渣      侯\n",
       "67  尹鸿涛   66   23   34  123  68  男       很差    不及格     学渣      尹\n",
       "\n",
       "[68 rows x 11 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出所有学生的姓氏\n",
    "\n",
    "def get_x(name):\n",
    "    return name[0]\n",
    "student_grade['name_x'] = student_grade.name.map(get_x)\n",
    "student_grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "dfb294f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>yw</th>\n",
       "      <th>sx</th>\n",
       "      <th>yy</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>262</td>\n",
       "      <td>286</td>\n",
       "      <td>288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>262</td>\n",
       "      <td>270</td>\n",
       "      <td>288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>254</td>\n",
       "      <td>278</td>\n",
       "      <td>284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>246</td>\n",
       "      <td>296</td>\n",
       "      <td>272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>252</td>\n",
       "      <td>270</td>\n",
       "      <td>280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>180</td>\n",
       "      <td>58</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>156</td>\n",
       "      <td>90</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>172</td>\n",
       "      <td>64</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>150</td>\n",
       "      <td>46</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>132</td>\n",
       "      <td>46</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     yw   sx   yy\n",
       "0   262  286  288\n",
       "1   262  270  288\n",
       "2   254  278  284\n",
       "3   246  296  272\n",
       "4   252  270  280\n",
       "..  ...  ...  ...\n",
       "63  180   58  128\n",
       "64  156   90   94\n",
       "65  172   64   92\n",
       "66  150   46   68\n",
       "67  132   46   68\n",
       "\n",
       "[68 rows x 3 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# apply\n",
    "# apply 方法可以对df中每一个值进行执行函数\n",
    "#   并且apply也可以应用在Series中\n",
    "def func4(x):\n",
    "    return x * 2\n",
    "\n",
    "student_grade[['yw','sx','yy']].apply(func=func4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "bb948a44",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     262\n",
       "1     262\n",
       "2     254\n",
       "3     246\n",
       "4     252\n",
       "     ... \n",
       "63    180\n",
       "64    156\n",
       "65    172\n",
       "66    150\n",
       "67    132\n",
       "Name: yw, Length: 68, dtype: int64"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_grade['yw'].apply(func=func4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a23e7a8b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cea74098",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf78826c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c7c0d57",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
